package br.inf.solutions.apresentacoes.ssp.control.validator;

import java.util.Date;
import java.util.Map;

import br.com.vexillum.util.Return;
import br.inf.solutions.apresentacoes.ssp.model.ParametrizationRemoval;

public class ParametrizationRemovalValidator extends BaseValidator {

	public ParametrizationRemovalValidator(Map<String, Object> mapData) {
		super(mapData);
	}
	
	@Override
	public Return validateSave() {
		Return ret = super.validateSave();
		if(ret.isValid()){
			ret.concat(enactmentOfLaw());
		}
		return ret;
	}
	
	@Override
	public Return validateUpdate() {
		Return ret = super.validateUpdate();
		if(ret.isValid()){
			ret.concat(enactmentOfLaw());
		}
		return ret;
	}
	
	private Return enactmentOfLaw(){
		Return ret = new Return(true);
		ParametrizationRemoval param = (ParametrizationRemoval) entity;
		Date startDate = param.getInitialDate();
		Date finalDate = param.getFinalDate();
		if(finalDate != null){
			if(finalDate.before(startDate)){
				ret.concat(creatReturn("finalDate", getValidationMessage(null, "enactmentoflawvalid", false)));
			}
		}
		return ret;
	}

}
